
var vm = new Vue({
	el:'#rrapp',
	data:{
        dialogVisible: false,
        q: { regionNameStart: null, regionNameEnd: null},
        page: {currentPage: 0, pageSizes: [15, 50, 100], pageSize: 15, total: 0, ascending: [], descending: []},
		showList: true,
		title: null,
        freightBaseList:[],
		freightBase: {},
        loading: null,
	},
	mounted: function () {
		this.search();
    },
	methods: {
        search: function () {
            this.page.currentPage = 1;
            this.queryFreightBase();
        },
        // 查询
        queryFreightBase: function () {
            //查询参数
            var queryParam = this.q;

            // 分页参数
            queryParam.page = this.page.currentPage;
            queryParam.limit = this.page.pageSize;


            //ajax 请求
            var self = this;
            $.ajax({
                type: "POST",
                url: baseURL + "freightBase/freightbase/list",
                contentType: "application/json;charset=UTF-8",
                data: JSON.stringify(queryParam),
                success: function (r) {
                    if (r.code == 0) {
                        self.page.total = r.page.totalCount;
                        self.freightBaseList = r.page.list;
                    } else {
                        alert(r.msg);
                    }
                }
            });


        },
        // 页数变化
        handleSizeChange: function (val) {
            this.page.pageSize = val;
            this.queryFreightBase();
        },
        //当前页变化
        handleCurrentChange: function (val) {
            this.page.currentPage = val;
            this.queryFreightBase();
        },

        openImport: function () {
			this.dialogVisible = true;
        },
        submitUpload: function () {
            this.$refs.upload.submit();
             this.loading = this.$loading({
                lock: true,
                text: '数据导入中,请勿刷新页面!',
                spinner: 'el-icon-loading',
            });
        },
        handleAvatarSuccess: function (data) {
            this.loading.close();
            if(data.code == 0){
        		this.dialogVisible = false;
        		this.search();
                this.$message({
                    message: '导入成功',
                    type: 'success'
                });
			}else {
        		alert(data.msg);
			}
        },
        handleAvatarError: function (error) {
            this.loading.close();
			alert(error);
        },
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.freightBase = {};
		},
		update: function (event) {
			var baseId = getSelectedRow();
			if(baseId == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(baseId)
		},
		saveOrUpdate: function (event) {
			var url = vm.freightBase.baseId == null ? "freightBase/freightbase/save" : "freightBase/freightbase/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.freightBase),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							//vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var baseIds = getSelectedRows();
			if(baseIds == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "freightBase/freightbase/delete",
                    contentType: "application/json",
				    data: JSON.stringify(baseIds),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								//$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(baseId){
			$.get(baseURL + "freightBase/freightbase/info/"+baseId, function(r){
                vm.freightBase = r.freightBase;
            });
		},
	}
});